@model IEnumerable<B.S.XZYData.Domain.LJC.Dto.WorkOrderReportViewDto>
@{
    ViewData["Title"] = "工单执行进度";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5 class="mb-0">工单执行进度</h5>
        <div>
            <button id="btnRefresh" class="btn btn-sm btn-primary">刷新</button>
        </div>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-sm table-bordered table-hover" id="tblWorkOrderReport">
                <thead class="thead-light">
                    <tr>
                        <th>工单编号</th>
                        <th>产品编号</th>
                        <th>产品名称</th>
                        <th>规格</th>
                        <th>计划数</th>
                        <th>良品数</th>
                        <th>不良数</th>
                        <th>报工时长(h)</th>
                        <th>进度</th>
                        <th>状态</th>
                        <th>创建时间</th>
                    </tr>
                </thead>
                <tbody>
                @foreach (var item in Model ?? Enumerable.Empty<B.S.XZYData.Domain.LJC.Dto.WorkOrderReportViewDto>())
                {
                    <tr>
                        <td>@item.WorkOrderCode</td>
                        <td>@item.ProductCode</td>
                        <td>@item.ProductName</td>
                        <td>@item.Spec</td>
                        <td>@item.PlannedQuantity</td>
                        <td>@item.GoodQuantity</td>
                        <td>@item.BadQuantity</td>
                        <td>@item.ReportHours</td>
                        <td>@item.Progress</td>
                        <td>@item.Status</td>
                        <td>@item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
                    </tr>
                }
                </tbody>
            </table>
        </div>
    </div>
</div>

@section Scripts{
<script>
    $(function(){
        $('#btnRefresh').on('click', function(){
            loadData();
        });

        function loadData(){
            $.ajax({
                url: '@Url.Action("GetWorkOrderReportList", "WorkOrderReport")',
                type: 'GET',
                data: { index: 1, size: 50 },
                success: function(res){
                    if(res && res.success && res.data && res.data.pageData){
                        var rows = res.data.pageData;
                        var html = '';
                        rows.forEach(function(item){
                            html += '<tr>'+
                                '<td>' + (item.workOrderCode||'') + '</td>'+
                                '<td>' + (item.productCode||'') + '</td>'+
                                '<td>' + (item.productName||'') + '</td>'+
                                '<td>' + (item.spec||'') + '</td>'+
                                '<td>' + (item.plannedQuantity||'') + '</td>'+
                                '<td>' + (item.goodQuantity||'') + '</td>'+
                                '<td>' + (item.badQuantity||'') + '</td>'+
                                '<td>' + (item.reportHours||'') + '</td>'+
                                '<td>' + (item.progress||'') + '</td>'+
                                '<td>' + (item.status||'') + '</td>'+
                                '<td>' + (item.createTime ? item.createTime.replace('T',' ') : '') + '</td>'+
                            '</tr>';
                        });
                        $('#tblWorkOrderReport tbody').html(html);
                    }else{
                        layer && layer.msg ? layer.msg(res.message || '获取失败') : alert(res.message || '获取失败');
                    }
                },
                error: function(){
                    layer && layer.msg ? layer.msg('请求失败') : alert('请求失败');
                }
            });
        }

        // 初次加载
        loadData();
    });
</script>
}


